/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.trandio.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.naming.NamingException;
import org.trandio.model.PaisVO;
import org.trandio.util.ConexionDb;

/**
 *
 * @author root
 */
public class PaisDAO implements IPais {

    public List<PaisVO> consultarPais() throws NamingException, SQLException {
        ConexionDb con = new ConexionDb();
        Connection conn;
        conn = con.traerConexion();

        List<PaisVO> listPais = new ArrayList<PaisVO>();

        String sql="select * from tbpais";

         PreparedStatement stmt = conn.prepareStatement(sql);

         try{
         ResultSet res = stmt.executeQuery();
         try{
            while (res.next()) {
                PaisVO pais = new PaisVO();
                pais.setId(res.getInt("id"));
                pais.setCodigo(res.getString("codigo"));
                pais.setDescripcion(res.getString("descripcion"));
                listPais.add(pais);
            }
            }finally{
             res.close();
         }
         }finally{
             stmt.close();
             if (!conn.isClosed())
               conn.close();
         }

        return listPais;
    }

}
